<?php


namespace app\admin\model;

use think\Model;
class Chartoilinve extends Model
{
    //获取时间段用的
    public function getDaysList($starttime,$endtime)
    {
        $starttime = $starttime?$starttime:date('Y-m-d');
        $endtime = $endtime?$endtime:date('Y-m-d',time()+(24*3600*7));
        $arr=periodDate($starttime,$endtime);
        return $arr;
    }

    //获取巡检数据用的
    public function getOilinvedataList($days,$admin)
    {
        if(count($days)==0){
            return [];
        }
        $arr = [];
        foreach($days as $k => $v){
            // 时间区间查询
            $where = [];
            $where['createtime'] = ['between time',[$v,$v.' 23:23:59']];
            if($admin){
                $where['admin_id'] = ['=',$admin];
            }

            $arr['inventory'][]=Oilinventory::where($where)->sum('inventory');

            $arr['comein'][]=Oilinventory::where($where)->sum('comein');

            $arr['used'][]=Oilinventory::where($where)->sum('used');
        }
        return $arr;
    }
}